package com.elite.groovy.callback;
import groovy.json.*;
import groovy.swing.impl.DefaultAction;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.RequestDispatcher;
import com.elite.groovy.util.EliteBean;
import java.security.MessageDigest;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.dom4j.Document
import org.dom4j.DocumentHelper
import org.dom4j.Element


import com.wisdge.dataservice.Result;
import com.wisdge.web.springframework.SpringContextUtil;
import java.util.Map;
import java.util.Date;
import java.util.HashMap;
import org.json.JSONObject;
import org.json.JSONArray;
import org.json.JSONException;
import com.elite.groovy.util.Util;
import cn.com.khproc.jsonCallProcedure;
import javax.sql.DataSource;
import cn.com.khproc.TPXMLToJson;
import cn.com.tpUtil.GetXMLValue;
import cn.com.tpUtil.SendPost;


import java.io.File;
import java.util.Iterator;
import java.util.List;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.json.JSONObject;

public class vehicleInsuranceService implements ServiceBackInvoke{
	private static final Log log=LogFactory.getLog(vehicleInsuranceService.class);
	public String doCallBack(EliteBean eliteBean, HttpServletRequest request, HttpServletResponse response) {
		response.setCharacterEncoding("UTF-8");

		String getMethod = request.getMethod();
		log.debug("getMethod:" + getMethod);
		
		String inData = "";
		String outData = "";
		String reData = "";
		String reData4 = "";
		String reData5 = "";
		String reData6 = "";
		String reData7 = "";
		String reData8 = "";
		String dataSourceID = "dataSource";
		String INPROPOSAL_NO = "";
		String inRequestType = "";
		String SyncJson="";
		String tFlag="";
		String Request_Type="";//返回类型
		String Response_Code="";//返回代码
		String Error_Message="";//返回描述
		String REQUESTTYPE="";
		BufferedReader iny = null;
		if (getMethod.equals("GET")) {
			inData = request.getParameter("data");
			log.debug("原始Get请求参数:" + inData);
		} else {
			InputStreamReader reader = new InputStreamReader(request.getInputStream(), "UTF-8");
			iny = new BufferedReader(reader);
			String line;
			while ((line = iny.readLine()) != null) {
				inData += line;
			}
			log.debug("原始Post请求参数:" + inData);
		}
		try{
			JSONObject jsonObject1 = new JSONObject(inData);
			inRequestType=GetJV(jsonObject1, "Sync_Type");
			if(inRequestType==""){
			inRequestType=GetJV(jsonObject1, "sync_type");
			}
			reData4 = GetJV(jsonObject1, "IN4");
			reData5 = GetJV(jsonObject1, "IN5");
			reData6 = GetJV(jsonObject1, "IN6");
			reData7 = GetJV(jsonObject1, "IN7");
			reData8 = GetJV(jsonObject1, "IN8");
			log.debug("返回reData6：" +reData6);
			log.debug("inRequestType:" + inRequestType);
			log.debug("inData:" + inData)
			try{
				if(inRequestType=="N1"){
					INPROPOSAL_NO = GetJV(jsonObject1, "I_OFFERNO");
					outData = jsonCallProcedure.doService(inData);
				}
				else if(inRequestType=="N2"){
					INPROPOSAL_NO = GetJV(jsonObject1, "I_appId");
					outData = jsonCallProcedure.doService(inData);
				}
				else if(inRequestType=="N3"){
					INPROPOSAL_NO = GetJV(jsonObject1, "I_qt_id");
					outData = jsonCallProcedure.doService(inData);
				}
				else if(inRequestType=="N4"){
								
				if(reData4!=""){
				
				JSONObject reData4json = new JSONObject(reData4);
				INPROPOSAL_NO = GetJV(reData4json, "I_qt_id");
				def I_Sync_Type= GetJV(reData4json, "Sync_Type");
				
				outData = jsonCallProcedure.doService(reData4);
				
				def insertSQL2="insert into qt_dm_ifc_log_new(id,offer_no,ifc_no,send_info,return_info,send_time,return_time) values (Sys_Guid(),'" + INPROPOSAL_NO + "','" + I_Sync_Type + "','" + reData4 + "','" + outData + "',sysdate,sysdate)";
				eliteBean.update(insertSQL2,'dataSource');
				}
				if(reData5!=""){
				JSONArray jsonArray = new JSONArray(reData5);
				int dataArrayLen = jsonArray.length();
				//log.debug("长度:" + dataArrayLen);
				JSONObject dataObject = null;
				def OUTArray="";
				for(int i = 0; i < dataArrayLen; i++) {
				dataObject = jsonArray.getJSONObject(i);
				//log.debug("内容:" + dataObject);
				def I_CONTACT_PHONE = GetJV(dataObject, "I_CONTACT_PHONE");
				def I_CONTACT_MOBILE_PHONE = GetJV(dataObject, "I_CONTACT_MOBILE_PHONE");
				def I_PERSON_OR_TEAM_FLAG = GetJV(dataObject, "I_PERSON_OR_TEAM_FLAG");
				def I_COUNTRY_CODE = GetJV(dataObject, "I_COUNTRY_CODE");
				def I_DEPARTMENT  = GetJV(dataObject, "I_DEPARTMENT");
				def I_RELATION_WITH_BRACH   = GetJV(dataObject, "I_RELATION_WITH_BRACH");
				def I_LEADER_NAME  = GetJV(dataObject, "I_LEADER_NAME");
				def I_LEADER_IDENTIFY_NUMBER = GetJV(dataObject, "I_LEADER_IDENTIFY_NUMBER");
				def I_LAUNDERING_SITUATION  = GetJV(dataObject, "I_LAUNDERING_SITUATION");
				def I_EMAIL  = GetJV(dataObject, "I_EMAIL");
				def I_OCCUPATION   = GetJV(dataObject, "I_OCCUPATION");
				def I_IDENTIFY_START_DATE   = GetJV(dataObject, "I_IDENTIFY_START_DATE");
				def I_IDENTIFY_END_DATE   = GetJV(dataObject, "I_IDENTIFY_END_DATE");
				def I_CONTACT_IDENTIFY_TYPE   = GetJV(dataObject, "I_CONTACT_IDENTIFY_TYPE");
				def I_CONTACT_IDENTIFY_NUMBER   = GetJV(dataObject, "I_CONTACT_IDENTIFY_NUMBER");
				def I_PHONE_HOLDER_NAME   = GetJV(dataObject, "I_PHONE_HOLDER_NAME");
				def I_PHONE_HOLDER_CERTITYPE  = GetJV(dataObject, "I_PHONE_HOLDER_CERTITYPE");
				def I_PHONE_HOLDER_CERTNUMBER = GetJV(dataObject, "I_PHONE_HOLDER_CERTNUMBER");
				def I_PHONE_HOLDER_TYPE = GetJV(dataObject, "I_PHONE_HOLDER_TYPE");
				def I_OPERATOR_TYPE   = GetJV(dataObject, "I_OPERATOR_TYPE");
				def I_CONTACT_PHONE_HOLDER_CERTITYPE  = GetJV(dataObject, "I_CONTACT_PHONE_HOLDER_CERTITYPE");
				def I_CONTACT_PHONE_HOLDER_NAME   = GetJV(dataObject, "I_CONTACT_PHONE_HOLDER_NAME");
				def I_CONTACT_PHONE_HOLDER_NUMBER  = GetJV(dataObject, "I_CONTACT_PHONE_HOLDER_NUMBER");
				def I_CONTACT_PHONE_HOLDER_TYPE   = GetJV(dataObject, "I_CONTACT_PHONE_HOLDER_TYPE");
				def I_IDENTIFY_LONG_TERN  = GetJV(dataObject, "I_IDENTIFY_LONG_TERN");
				def I_LONG_TERM_IDENTIFY_END_DATE  = GetJV(dataObject, "I_LONG_TERM_IDENTIFY_END_DATE");
				def I_INSURED_NATURE_JS  = GetJV(dataObject, "I_INSURED_NATURE_JS");
				def I_QT_ID    = GetJV(dataObject, "I_QT_ID");
				def I_PERSON_TYPE  = GetJV(dataObject, "I_PERSON_TYPE");
				def I_NAME     = GetJV(dataObject, "I_NAME");
				def I_CTEL_PHONE  = GetJV(dataObject, "I_CTEL_PHONE");
				def I_IDENTIFY_TYPE   = GetJV(dataObject, "I_IDENTIFY_TYPE");
				def I_IDENTIFY_NUMBER  = GetJV(dataObject, "I_IDENTIFY_NUMBER");
				def I_DEL_FLAG   = GetJV(dataObject, "I_DEL_FLAG");
				def I_CREATE_ID    = GetJV(dataObject, "I_CREATE_ID");
				def I_UPDATE_ID     = GetJV(dataObject, "I_UPDATE_ID");
				def I_MOBILE_PHONE   = GetJV(dataObject, "I_MOBILE_PHONE");
				def I_ADDR      = GetJV(dataObject, "I_ADDR");
				def I_CONTACT_NAME  = GetJV(dataObject, "I_CONTACT_NAME");
				def I_OWNER_NATURE  = GetJV(dataObject, "I_OWNER_NATURE");
				def I_PROFESSION   = GetJV(dataObject, "I_PROFESSION");
				def I_ISLIFEIND   = GetJV(dataObject, "I_ISLIFEIND");
				def I_Sync_Type   = GetJV(dataObject, "Sync_Type");
				def deleteSQL="Delete From PolicyHolderAndInsuredPersonInfo Where QT_ID= '" + I_QT_ID + "' and person_type= '" + I_PERSON_TYPE + "'";
				eliteBean.update(deleteSQL,'dataSource');

				def insertSQL="insert into PolicyHolderAndInsuredPersonInfo(ID,CONTACT_PHONE,CONTACT_MOBILE_PHONE,PERSON_OR_TEAM_FLAG,COUNTRY_CODE,DEPARTMENT,RELATION_WITH_BRACH,LEADER_NAME,LEADER_IDENTIFY_NUMBER,LAUNDERING_SITUATION,EMAIL,OCCUPATION,IDENTIFY_START_DATE,IDENTIFY_END_DATE,CONTACT_IDENTIFY_TYPE,CONTACT_IDENTIFY_NUMBER,PHONE_HOLDER_NAME,PHONE_HOLDER_CERTITYPE,PHONE_HOLDER_CERTNUMBER,PHONE_HOLDER_TYPE,OPERATOR_TYPE,CONTACT_PHONE_HOLDER_CERTITYPE,CONTACT_PHONE_HOLDER_NAME,CONTACT_PHONE_HOLDER_NUMBER,CONTACT_PHONE_HOLDER_TYPE,IDENTIFY_LONG_TERN,LONG_TERM_IDENTIFY_END_DATE,INSURED_NATURE_JS,QT_ID,PERSON_TYPE,NAME,CTEL_PHONE,IDENTIFY_TYPE,IDENTIFY_NUMBER,DEL_FLAG,CREATE_ID,MOBILE_PHONE,ADDR,CONTACT_NAME,Create_Date,OWNER_NATURE   ,PROFESSION        ,ISLIFEIND   ) values (sys_guid() || to_char(sysdate, 'yyyymmddhh24missss'),'" + I_CONTACT_PHONE + "','" + I_CONTACT_MOBILE_PHONE + "','" + I_PERSON_OR_TEAM_FLAG + "','" + I_COUNTRY_CODE + "','" + I_DEPARTMENT + "','" + I_RELATION_WITH_BRACH + "','" + I_LEADER_NAME + "','" + I_LEADER_IDENTIFY_NUMBER + "','" + I_LAUNDERING_SITUATION + "','" + I_EMAIL + "','" + I_OCCUPATION + "','" + I_IDENTIFY_START_DATE + "','" + I_IDENTIFY_END_DATE + "','" + I_CONTACT_IDENTIFY_TYPE + "','" + I_CONTACT_IDENTIFY_NUMBER + "','" + I_PHONE_HOLDER_NAME + "','" + I_PHONE_HOLDER_CERTITYPE + "','" + I_PHONE_HOLDER_CERTNUMBER + "','" + I_PHONE_HOLDER_TYPE + "','" + I_OPERATOR_TYPE + "','" + I_CONTACT_PHONE_HOLDER_CERTITYPE + "','" + I_CONTACT_PHONE_HOLDER_NAME + "','" + I_CONTACT_PHONE_HOLDER_NUMBER + "','" + I_CONTACT_PHONE_HOLDER_TYPE + "','" + I_IDENTIFY_LONG_TERN + "','" + I_LONG_TERM_IDENTIFY_END_DATE + "','" + I_INSURED_NATURE_JS + "','" + I_QT_ID + "','" + I_PERSON_TYPE + "','" + I_NAME + "','" + I_CTEL_PHONE + "','" + I_IDENTIFY_TYPE + "','" + I_IDENTIFY_NUMBER + "','" + I_DEL_FLAG + "','" + I_CREATE_ID + "','" + I_MOBILE_PHONE + "','" + I_ADDR + "','" + I_CONTACT_NAME + "',sysdate,'" + I_OWNER_NATURE + "','" + I_PROFESSION + "', '" + I_ISLIFEIND + "')";
				log.debug("新增SQL-N5:"+insertSQL);
				eliteBean.update(insertSQL,'dataSource');
				if(OUTArray == null || OUTArray.length() <= 0) {
				   outData = "{\"code\": 1,\"message\":\"投被保人信息处理成功\"}";
	
				}
				else {
				   outData = "{\"code\": 0,\"message\":\"投被保人信息处理异常\"}";
				}
				
				def insertSQL2="insert into qt_dm_ifc_log_new(id,offer_no,ifc_no,send_info,return_info,send_time,return_time) values (Sys_Guid(),'" + I_QT_ID + "','" + I_Sync_Type + "','" + dataObject + "','" + outData + "',sysdate,sysdate)";
				eliteBean.update(insertSQL2,'dataSource');
				
				}
				}
				if(reData6!=""){
				String str=reData6;
                str=str.replace("[","");
                str=str.replace("]","");
                log.debug("reData6json:" + str);				
				JSONObject reData6json = new JSONObject(str);
				def I_QT_IDN = GetJV(reData6json,"I_QT_ID");
				def deleteSQL="update RISKCODEINFO set DEAL_FLAG=0 Where QT_ID= '" + I_QT_IDN + "' and DEAL_FLAG=1";
				eliteBean.update(deleteSQL,'dataSource');
				log.debug("I_QT_IDN:" + I_QT_IDN);
				JSONArray jsonArray = new JSONArray(reData6);
				int dataArrayLen = jsonArray.length();
				//log.debug("长度:" + dataArrayLen);
				JSONObject dataObject = null;
				def OUTArray="";

				for(int i = 0; i < dataArrayLen; i++) {
				dataObject = jsonArray.getJSONObject(i);
				//log.debug("内容:" + dataObject);
				def I_CLAUSE_SYS_TYPE = GetJV(dataObject,"I_CLAUSE_SYS_TYPE");
				def I_PRODUCT_SYS_TYPE = GetJV(dataObject,"I_PRODUCT_SYS_TYPE");
				def I_SUM_ADD_TAX = GetJV(dataObject,"I_SUM_ADD_TAX");
				def I_SUM_ADD_TAX_RATE = GetJV(dataObject,"I_SUM_ADD_TAX_RATE");
				def I_SUM_PRICE_TAX_TOTAL = GetJV(dataObject,"I_SUM_PRICE_TAX_TOTAL");
				def I_IMMEFFECT_START_DATE = GetJV(dataObject,"I_IMMEFFECT_START_DATE");
				def I_TAKE_VALID_TYPE = GetJV(dataObject,"I_TAKE_VALID_TYPE");
				def I_IS_ELECTRONIC_PROPOSAL = GetJV(dataObject,"I_IS_ELECTRONIC_PROPOSAL");
				def I_ID = GetJV(dataObject,"I_ID");
				def I_QT_ID = GetJV(dataObject,"I_QT_ID");
				def I_RISK_CODE = GetJV(dataObject,"I_RISK_CODE");
				def I_START_DATE = GetJV(dataObject,"I_START_DATE");
				def I_END_DATE = GetJV(dataObject,"I_END_DATE");
				def I_INSURE_YEAR = GetJV(dataObject,"I_INSURE_YEAR");
				def I_PLAN_CODE = GetJV(dataObject,"I_PLAN_CODE");
				def I_CURRENCY = GetJV(dataObject,"I_CURRENCY");
				def I_COINS_IND = GetJV(dataObject,"I_COINS_IND");
				def I_TOTAL_SUM_INSURED = GetJV(dataObject,"I_TOTAL_SUM_INSURED");
				def I_TOTAL_PREMIUM = GetJV(dataObject,"I_TOTAL_PREMIUM");
				def I_CREATE_ID = GetJV(dataObject,"I_CREATE_ID");
				def I_UPDATE_ID = GetJV(dataObject,"I_UPDATE_ID");
				def I_BUSINESS_LEVEL = GetJV(dataObject,"I_BUSINESS_LEVEL");
				def I_RISK_POLICY_NO = GetJV(dataObject,"I_RISK_POLICY_NO");
				def I_FACTOR_CODEN03 = GetJV(dataObject,"I_FACTOR_CODEN03");
				def I_FACTOR_CODEN04 = GetJV(dataObject,"I_FACTOR_CODEN04");
				def I_FACTOR_CODEN05 = GetJV(dataObject,"I_FACTOR_CODEN05");
				def I_COREVALUE = GetJV(dataObject,"I_COREVALUE");
				def I_VEHICLE_TAX = GetJV(dataObject,"I_VEHICLE_TAX");
				def I_QUERY_SEQUENCE_NO = GetJV(dataObject,"I_QUERY_SEQUENCE_NO");
				def I_QUERY_SEQUENCE_DATE = GetJV(dataObject,"I_QUERY_SEQUENCE_DATE");
				def I_FACTOR_CODEN01 = GetJV(dataObject,"I_FACTOR_CODEN01");
				def I_FACTOR_CODEN02 = GetJV(dataObject,"I_FACTOR_CODEN02");
				def I_MARGINALRATE = GetJV(dataObject,"I_MARGINALRATE");
				def I_Product_code = GetJV(dataObject,"Product_code");
				def I_Quota_code = GetJV(dataObject,"Quota_code");
				def I_Sync_Type   = GetJV(dataObject, "Sync_Type");

				def insertSQL="insert into RISKCODEINFO(CLAUSE_SYS_TYPE,PRODUCT_SYS_TYPE,SUM_ADD_TAX,SUM_ADD_TAX_RATE,SUM_PRICE_TAX_TOTAL,IMMEFFECT_START_DATE,TAKE_VALID_TYPE,IS_ELECTRONIC_PROPOSAL,ID,QT_ID,RISK_CODE,START_DATE,END_DATE,INSURE_YEAR,PLAN_CODE,CURRENCY,COINS_IND,TOTAL_SUM_INSURED,TOTAL_PREMIUM,CREATE_ID,CREATE_DATE,BUSINESS_LEVEL,RISK_POLICY_NO,FACTOR_CODEN03,FACTOR_CODEN04,FACTOR_CODEN05,COREVALUE,VEHICLE_TAX,QUERY_SEQUENCE_NO,QUERY_SEQUENCE_DATE,FACTOR_CODEN01,FACTOR_CODEN02,DEAL_FLAG,MARGINALRATE,Product_code,Quota_code) values ('" + I_CLAUSE_SYS_TYPE + "','" + I_PRODUCT_SYS_TYPE + "','" + I_SUM_ADD_TAX + "','" + I_SUM_ADD_TAX_RATE + "','" + I_SUM_PRICE_TAX_TOTAL + "','" + I_IMMEFFECT_START_DATE + "','" + I_TAKE_VALID_TYPE + "','" + I_IS_ELECTRONIC_PROPOSAL + "','" + I_ID + "','" + I_QT_ID + "','" + I_RISK_CODE + "','" + I_START_DATE + "','" + I_END_DATE + "','" + I_INSURE_YEAR + "','" + I_PLAN_CODE + "','" + I_CURRENCY + "','" + I_COINS_IND + "','" + I_TOTAL_SUM_INSURED + "','" + I_TOTAL_PREMIUM + "','" + I_CREATE_ID + "',sysdate,'" + I_BUSINESS_LEVEL + "','" + I_RISK_POLICY_NO + "','" + I_FACTOR_CODEN03 + "','" + I_FACTOR_CODEN04 + "','" + I_FACTOR_CODEN05 + "','" + I_COREVALUE + "','" + I_VEHICLE_TAX + "','" + I_QUERY_SEQUENCE_NO + "','" + I_QUERY_SEQUENCE_DATE + "','" + I_FACTOR_CODEN01 + "','" + I_FACTOR_CODEN02 + "',1,'" + I_MARGINALRATE + "','" + I_Product_code + "','" + I_Quota_code + "')";
				//log.debug("新增SQL-N6:"+insertSQL);
				eliteBean.update(insertSQL,'dataSource');
				if(OUTArray == null || OUTArray.length() <= 0) {
				   outData = "{\"code\": 1,\"message\":\"险种信息处理成功\"}";
	
				}
				else {
				   outData = "{\"code\": 0,\"message\":\"险种信息处理异常\"}";
				}
				def insertSQL2="insert into qt_dm_ifc_log_new(id,offer_no,ifc_no,send_info,return_info,send_time,return_time) values (Sys_Guid(),'" + I_QT_ID + "','" + I_Sync_Type + "','" + dataObject + "','" + outData + "',sysdate,sysdate)";
				eliteBean.update(insertSQL2,'dataSource');
				
				}
				
				}
				if(reData8!=""){
				JSONObject reDatajson = new JSONObject(reData8);
				INPROPOSAL_NO = GetJV(reDatajson, "I_QT_ID");
				def I_Sync_Type= GetJV(reDatajson, "Sync_Type");
				outData = jsonCallProcedure.doService(reData8);
				
				def insertSQL2="insert into qt_dm_ifc_log_new(id,offer_no,ifc_no,send_info,return_info,send_time,return_time) values (Sys_Guid(),'" + INPROPOSAL_NO + "','" + I_Sync_Type + "','" + reData8 + "','" + outData + "',sysdate,sysdate)";
				log.debug("处理reData8:"+insertSQL2);
				eliteBean.update(insertSQL2,'dataSource');
				}
				if(reData7!=""){
				String str=reData7;
                str=str.replace("[","");
                str=str.replace("]","");
                log.debug("reData7json:" + str);				
				JSONObject reData7json = new JSONObject(str);
				def I_risk_idn = GetJV(reData7json,"I_risk_id");
				def I_risk_coden = GetJV(reData7json,"I_risk_code");
				def deleteSQL="update RISKITEMINFO set DEAL_FLAG=0 Where risk_id in (select  r.id from  riskcodeinfo r  where   r.qt_id in (select qt_id from riskcodeinfo r  where   r.id='" + I_risk_idn + "' ) and r.deal_flag=1)";
				eliteBean.update(deleteSQL,'dataSource');
				JSONArray jsonArray = new JSONArray(reData7);
				int dataArrayLen = jsonArray.length();
				JSONObject dataObject = null;
				def OUTArray="";
				for(int i = 0; i < dataArrayLen; i++) {
				dataObject = jsonArray.getJSONObject(i);
				//log.debug("内容:" + dataObject);
				def I_id = GetJV(dataObject, "I_id");
				def I_risk_id = GetJV(dataObject, "I_risk_id");
				def I_risk_code = GetJV(dataObject, "I_risk_code");
				def I_kind_ind = GetJV(dataObject, "I_kind_ind");
				def I_kind_code = GetJV(dataObject, "I_kind_code");
				def I_kind_name = GetJV(dataObject, "I_kind_name");
				def I_kind_item_no = GetJV(dataObject, "I_kind_item_no");
				def I_sum_insured = GetJV(dataObject, "I_sum_insured");
				def I_every_sum_insured = GetJV(dataObject, "I_every_sum_insured");
				def I_isinsured_no_deductible = GetJV(dataObject, "I_isinsured_no_deductible");
				def I_deductible = GetJV(dataObject, "I_deductible");
				def I_value_type = GetJV(dataObject, "I_value_type");
				def I_short_rate_flag = GetJV(dataObject, "I_short_rate_flag");
				def I_deductible_rate = GetJV(dataObject, "I_deductible_rate");
				def I_surrender_ind = GetJV(dataObject, "I_surrender_ind");
				def I_kind_flag = GetJV(dataObject, "I_kind_flag");
				def I_base_premium = GetJV(dataObject, "I_base_premium");
				def I_rate = GetJV(dataObject, "I_rate");
				def I_benchmark_premium = GetJV(dataObject, "I_benchmark_premium");
				def I_gross_premium = GetJV(dataObject, "I_gross_premium");
				def I_discount = GetJV(dataObject, "I_discount");
				def I_start_date = GetJV(dataObject, "I_start_date");
				def I_end_date = GetJV(dataObject, "I_end_date");
				def I_currency = GetJV(dataObject, "I_currency");
				def I_calculate_ind = GetJV(dataObject, "I_calculate_ind");
				def I_rate_period = GetJV(dataObject, "I_rate_period");
				def I_net_premium = GetJV(dataObject, "I_net_premium");
				def I_franchise = GetJV(dataObject, "I_franchise");
				def I_short_rate = GetJV(dataObject, "I_short_rate");
				def I_add_itional_rate = GetJV(dataObject, "I_add_itional_rate");
				def I_all_broken_rate = GetJV(dataObject, "I_all_broken_rate");
				def I_pure_bench_premium = GetJV(dataObject, "I_pure_bench_premium");
				def I_no_debt_premium = GetJV(dataObject, "I_no_debt_premium");
				def I_base_pure_bench_premium = GetJV(dataObject, "I_base_pure_bench_premium");
				def I_add_tax = GetJV(dataObject, "I_add_tax");
				def I_add_tax_rate = GetJV(dataObject, "I_add_tax_rate");
				def I_price_tax_total = GetJV(dataObject, "I_price_tax_total");
				def I_suit_product = GetJV(dataObject, "I_suit_product");
				def I_assist_kind_flag = GetJV(dataObject, "I_assist_kind_flag");
				def I_INSURED_SEATS_DAYS = GetJV(dataObject, "I_INSURED_SEATS_DAYS");
				def I_servicetimes = GetJV(dataObject, "I_servicetimes");
				def I_Sync_Type   = GetJV(dataObject, "Sync_Type");
				//def deleteSQL="Delete From RISKITEMINFO Where risk_id= '" + I_risk_id + "' and risk_code='" + I_risk_code + "' and kind_code='" + I_kind_code + "' ";
				//eliteBean.update(deleteSQL,'dataSource');
				def insertSQL="Insert Into RISKITEMINFO (id, risk_id,RISK_CODE,KIND_IND,KIND_CODE,KIND_NAME,KIND_ITEM_NO,SUM_INSURED,EVERY_SUM_INSURED,ISINSURED_NO_DEDUCTIBLE,DEDUCTIBLE,VALUE_TYPE,SHORT_RATE_FLAG,DEDUCTIBLE_RATE,SURRENDER_IND,KIND_FLAG,BASE_PREMIUM,RATE,BENCHMARK_PREMIUM,GROSS_PREMIUM,DISCOUNT,START_DATE,END_DATE,CURRENCY,CALCULATE_IND,CREATE_DATE,RATE_PERIOD,NET_PREMIUM,FRANCHISE,SHORT_RATE,ADD_ITIONAL_RATE,ALL_BROKEN_RATE,PURE_BENCH_PREMIUM,NO_DEBT_PREMIUM,BASE_PURE_BENCH_PREMIUM,ADD_TAX,ADD_TAX_RATE,PRICE_TAX_TOTAL,SUIT_PRODUCT,ASSIST_KIND_FLAG,INSURED_SEATS_DAYS,servicetimes,deal_flag) Values ('XBXX' || Sys_Guid(), '" + I_risk_id + "', '" + I_risk_code + "', '" + I_kind_ind + "', '" + I_kind_code + "', '" + I_kind_name + "', '" + I_kind_item_no + "', '" + I_sum_insured + "', '" + I_every_sum_insured + "', '" + I_isinsured_no_deductible + "', '" + I_deductible + "', '" + I_value_type + "', '" + I_short_rate_flag + "', '" + I_deductible_rate + "', '" + I_surrender_ind + "', '" + I_kind_flag + "', '" + I_base_premium + "', '" + I_rate + "', '" + I_benchmark_premium + "', '" + I_gross_premium + "', '" + I_discount + "', to_date('" + I_start_date + "','yyyy-mm-dd hh24:mi:ss'),to_date('" + I_end_date + "','yyyy-mm-dd hh24:mi:ss'), '" + I_currency + "', '" + I_calculate_ind + "',sysdate, '" + I_rate_period + "', '" + I_net_premium + "', '" + I_franchise + "', '" + I_short_rate + "', '" + I_add_itional_rate + "', '" + I_all_broken_rate + "', '" + I_pure_bench_premium + "', '" + I_no_debt_premium + "', '" + I_base_pure_bench_premium + "', '" + I_add_tax + "', '" + I_add_tax_rate + "', '" + I_price_tax_total + "', '" + I_suit_product + "', '" + I_assist_kind_flag + "', '" + I_INSURED_SEATS_DAYS + "', '" + I_servicetimes + "',1)";
				//log.debug("新增SQL:"+insertSQL);
				eliteBean.update(insertSQL,'dataSource');
				if(OUTArray == null || OUTArray.length() <= 0) {
				   outData = "{\"code\": 1,\"message\":\"数据处理成功\"}";
	
				}
				else {
				   outData = "{\"code\": 0,\"message\":\"数据处理异常\"}";
				}
				def insertSQLtwo="insert into qt_dm_ifc_log_new(id,offer_no,ifc_no,send_info,return_info,send_time,return_time) values (Sys_Guid(),'" + I_risk_id + "','" + I_Sync_Type + "','" + dataObject + "','" + outData + "',sysdate,sysdate)";
				log.debug("insertSQLtwo:"+insertSQLtwo);
				eliteBean.update(insertSQLtwo,'dataSource');
				
				}
					
					return outData;
				}
				}
				else if (inRequestType=="N9") {
				  INPROPOSAL_NO = GetJV(jsonObject1, "ORDERID");
				  outData = jsonCallProcedure.doService(inData);
				}
				else if (inRequestType=="N10") {
					INPROPOSAL_NO = GetJV(jsonObject1, "ORDERID");
					outData = jsonCallProcedure.doService(inData);
				  }
				else if (inRequestType=="N11") {
					INPROPOSAL_NO = GetJV(jsonObject1, "I_QT_ID");
					outData = jsonCallProcedure.doService(inData);
				  }
				else if (inRequestType=="N12") {
					INPROPOSAL_NO = GetJV(jsonObject1, "ORDERID");
					outData = jsonCallProcedure.doService(inData);
				  }
				else if (inRequestType=="N13") {
					INPROPOSAL_NO = GetJV(jsonObject1, "Ticket");
					outData = jsonCallProcedure.doService(inData);
				  }
				else if (inRequestType=="N14") {
				INPROPOSAL_NO = GetJV(jsonObject1, "i_agentid");
				outData = jsonCallProcedure.doService(inData);
				  }
				else
				{
					tFlag="1";
					outData = "{\"code\": 0,\"message\":\"未知的数据接口类型\"}";
				}
				
			}catch(Exception e){
				log.error("接口处理异常"+e.getMessage());
				outData = "{\"code\": 0,\"message\":\""+ e.getMessage() +"\"}";
				log.debug("处理失败返回JSON:" + outData);
				return outData;
			}
		}catch(Exception e){
			
			try{
				inRequestType = GetXMLValue.readStringXml(inData, "REQUEST_TYPE");
				log.debug("inRequestType:" + inRequestType);

				//报价单状态回写电销系统
				if(inRequestType=="A1")
				{
					//将第三方系统的XML报文中的BODY内容加上接口类型直接转为JSON
					INPROPOSAL_NO = GetXMLValue.readXml(inData, "BASE_PART", "APP_ID");
					SyncJson = TPXMLToJson.toJson(inRequestType, "BASE_PART", inData);
					// 将JSON直接调用jsonCallProcedure方法完成JSON到存储过程的调用并接收返回JSON字符串
					outData = jsonCallProcedure.doService(SyncJson);

				}
				else if(inRequestType=="A11")
				{
					//SyncJson = TPXMLToJson.toJson(inRequestType, "BASE_PART", inData);
					//outData = jsonCallProcedure.doService(SyncJson);
					INPROPOSAL_NO = GetXMLValue.readXml(inData, "BASE_PART", "APP_ID");
					outData = TPXMLToJson.toJson2(inRequestType, "BASE_PART", inData);
					def insertSQL="insert into qt_dm_ifc_log_new(id,offer_no,ifc_no,send_info,return_info,send_time,return_time) values (Sys_Guid(),'" + INPROPOSAL_NO + "','" + inRequestType + "','" + inData + "','" + outData + "',sysdate,sysdate)";
					//log.debug("新增SQL-A11:"+SyncJson);
					eliteBean.update(insertSQL,'dataSource');

				}
				//转介绍信息提交到电销系统
				else if(inRequestType=="A2")
				{
					SyncJson = TPXMLToJson.toJson(inRequestType, "BASE_PART", inData);

					outData = jsonCallProcedure.doService(SyncJson);

				}
				//投保单信息回写电销系统
				else if(inRequestType=="A3")
				{
					INPROPOSAL_NO = GetXMLValue.readXml(inData, "BASE_PART", "APP_ID");
					SyncJson = TPXMLToJson.toJson(inRequestType, "BASE_PART", inData);

					outData = jsonCallProcedure.doService(SyncJson);

				}
				else if(inRequestType=="A31")
				{
					INPROPOSAL_NO = GetXMLValue.readXml(inData, "BASE_PART", "APP_ID");
					def deleteSQL="delete from Quotation_Nocar q where q.quotation_id = '" + INPROPOSAL_NO + "'";
					log.debug("A31deleteSQL:" + deleteSQL);
				    eliteBean.update(deleteSQL,'dataSource');
					outData = TPXMLToJson.toJson2(inRequestType, "BASE_PART", inData);
					

				}
				//A4复核查询接口
				else if(inRequestType=="A4")
				{
					SyncJson = TPXMLToJson.toJson(inRequestType, "BASE_PART", inData);

					outData = jsonCallProcedure.doService(SyncJson);

				}
				//蚂蚁名单推送
				else if(inRequestType=="WDMYMD")
				{

					SyncJson = TPXMLToJson.toJson(inRequestType, "BODY", inData);

					outData = jsonCallProcedure.doService(SyncJson);

				}
				//蚂蚁名单受理时间回写
				else if(inRequestType=="MYTH")
				{

					SyncJson = TPXMLToJson.toJson(inRequestType, "BASE_PART", inData);

					outData = jsonCallProcedure.doService(SyncJson);

				}
				//蚂蚁名单支付状态回写
				else if(inRequestType=="ZFQR")
				{

					SyncJson = TPXMLToJson.toJson(inRequestType, "BASE_PART", inData);

					outData = jsonCallProcedure.doService(SyncJson);

				}
				//蚂蚁名单承保状态回写
				else if(inRequestType=="CBQR")
				{

					SyncJson = TPXMLToJson.toJson(inRequestType, "BASE_PART", inData);

					outData = jsonCallProcedure.doService(SyncJson);

				}
				//与太平IT核实此功能暂未使用，蚂蚁名单投保查询接口
				else if(inRequestType=="TBCX")
				{

					SyncJson = TPXMLToJson.toJson(inRequestType, "BODY", inData);

					outData = jsonCallProcedure.doService(SyncJson);

				}
				//网销网电名单推送
				else if(inRequestType=="W2")
				{
				    INPROPOSAL_NO = GetXMLValue.readXml(inData, "BASE_PART", "SYS_ID2");
					
					SyncJson = TPXMLToJson.toJson(inRequestType, "BASE_PART", inData);

					outData = jsonCallProcedure.doService(SyncJson);

				}
				//网销系统往电销系统回写收费信息
				else if(inRequestType=="W3")
				{

					SyncJson = TPXMLToJson.toJson(inRequestType, "BASE_PART", inData);

					outData = jsonCallProcedure.doService(SyncJson);

				}
				//网转电业务主接口
				else if(inRequestType=="W4")
				{

					SyncJson = TPXMLToJson.toJson(inRequestType, "BASE_PART", inData);

					outData = jsonCallProcedure.doService(SyncJson);

				}
				//意外险回写电销接口
				else if(inRequestType=="Y1")
				{

					SyncJson = TPXMLToJson.toJson(inRequestType, "BASE_PART", inData);

					outData = jsonCallProcedure.doService(SyncJson);

				}

				//第三方直接提交配送任务处理
				else if(inRequestType=="P1")
				{

					SyncJson = TPXMLToJson.toJson(inRequestType, "BASE_PART", inData);

					outData = jsonCallProcedure.doService(SyncJson);

				}
				//Z1电销坐席外拨信息反馈接口
				else if(inRequestType=="Z1")
				{

					SyncJson = TPXMLToJson.toJson(inRequestType, "BASE_PART", inData);

					outData = jsonCallProcedure.doService(SyncJson);

				}
				//Z1电销坐席外拨信息反馈接口
				else if(inRequestType=="S1")
				{

					SyncJson = TPXMLToJson.toJson(inRequestType, "BASE_PART", inData);

					outData = jsonCallProcedure.doService(SyncJson);

					JSONObject jObject = new JSONObject(outData);
					String needHandle=GetJV(jObject.get("data"), "needhandle");
					log.debug("存储过程返回Needhandle信息:" + needHandle);

					if(needHandle=="1"){
						String PostURL=GetJV(jObject.get("data"), "url");
						String PostXml=GetJV(jObject.get("data"), "param");

						SendPost sendsms = new SendPost();
						String coreResult = sendsms.main(PostURL, PostXml);
						log.debug("发送调用核心pay002接口返回信息:" + coreResult);

						Request_Type = GetXMLValue.main(coreResult, "REQUEST_TYPE");
						Response_Code = GetXMLValue.main(coreResult, "RESPONSE_CODE");
						Error_Message = GetXMLValue.main(coreResult, "ERROR_MESSAGE");
						return "<?xml version=\"1.0\" encoding=\"UTF-8\"?><PACKET TYPE=\"REQUEST\" VERSION=\"1.0\"><HEAD><REQUEST_TYPE>"+inRequestType+"</REQUEST_TYPE><RESPONSE_CODE>"+Response_Code+"</RESPONSE_CODE><ERROR_MESSAGE>"+Error_Message+"</ERROR_MESSAGE></HEAD></PACKET>";
					}
					else
					{
						return "<?xml version=\"1.0\" encoding=\"UTF-8\"?><PACKET TYPE=\"REQUEST\" VERSION=\"1.0\"><HEAD><REQUEST_TYPE>"+inRequestType+"</REQUEST_TYPE><RESPONSE_CODE>1</RESPONSE_CODE><ERROR_MESSAGE></ERROR_MESSAGE></HEAD></PACKET>";
					}
				}
				else
				{
					tFlag="1";
					outData = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><PACKET TYPE=\"REQUEST\" VERSION=\"1.0\"><HEAD><REQUEST_TYPE>"+inRequestType+"</REQUEST_TYPE><RESPONSE_CODE>0</RESPONSE_CODE><ERROR_MESSAGE>未知的数据接口类型</ERROR_MESSAGE></HEAD></PACKET>";
				}

				
			}catch(Exception e1){
				log.error("接口处理异常"+e1.getMessage());
				outData = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><PACKET TYPE=\"REQUEST\" VERSION=\"1.0\"><HEAD><REQUEST_TYPE>"+inRequestType+"</REQUEST_TYPE><RESPONSE_CODE>0</RESPONSE_CODE><ERROR_MESSAGE>"+e1.getMessage()+"</ERROR_MESSAGE></HEAD></PACKET>";
				log.debug("处理失败返回XML:" + outData);
				return 1;
			}
		

		}
			
			if(tFlag!="1"){
					JSONObject jsonObject = new JSONObject(outData);
					// JSONObject jsonObject = JSONObject.parseObject(outData);
					// outData=jsonObject.getString("outstring");
					outData=GetJV(jsonObject.get("data"), "outstring");
				}
				else
				{
					log.debug("处理异常");
				}

				log.debug("处理"+inRequestType+"接口成功并返回JSON字符串Result_Json:" + outData);
				
				log.debug("处理"+inRequestType+"调用接口的字符串Result_Json:" + inData);
				log.debug("处理"+inRequestType+"接口成功并返回JSON字符串Result_Json:" + outData);
				//def insertSQL="insert into qt_dm_ifc_log_new(id,offer_no,ifc_no,send_info,return_info,send_time,return_time) values (Sys_Guid(),'" + INPROPOSAL_NO + "','" + inRequestType + "','" + inData + "','" + outData + "',sysdate,sysdate)";
			    def insertSQL="DECLARE  clobValue qt_dm_ifc_log_new.Send_Info%TYPE;  BEGIN  clobValue:='" + inData + "' ;   insert into qt_dm_ifc_log_new(id,offer_no,ifc_no,send_info,return_info,send_time,return_time) values (Sys_Guid(),'" + INPROPOSAL_NO + "','" + inRequestType + "',clobValue,'" + outData + "',sysdate,sysdate);   COMMIT; END;";
				eliteBean.update(insertSQL,'dataSource');
				return outData;
	}

	// 解析Json值
	public static String GetJV(JSONObject inJson, String getKey) {
		String Rev_Value = null;
		try {
			Rev_Value = inJson.getString(getKey);
		} catch (Exception e) {
			try {
				Rev_Value = String.valueOf(inJson.getInt(getKey));
			} catch (Exception e1) {
				try {
					Rev_Value = String.valueOf(inJson.getJSONArray(getKey));
				} catch (Exception e2) {
					try {
						Rev_Value = String.valueOf(inJson.getJSONObject(getKey));
					} catch (Exception e3) {

						try {
							Rev_Value = String.valueOf(inJson.getBoolean(getKey));
						} catch (Exception e4) {
							Rev_Value = "";
						}
					}
				}
			}
		} finally {
			if (Rev_Value == null || Rev_Value.equals("null") || Rev_Value.length() <= 0) {
				Rev_Value = "";
			} else {
			}
		}
		return Rev_Value;
	}
}
